<template>
  <div class="selfBartendLogin">
    <c-title :hide="false" text="扫码登录"></c-title>
    <div id="login_code"></div>
  </div>
</template>
<script>
import base64_encode from "../../utils/base64_encode";
export default {
  data() {
    return {};
  },
  activated() {
    this.getData();
  },
  methods: {
    getParam(name, url) {
      var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
      // var r = window.location.search.substr(1).match(reg);
      if (url.indexOf("?") > -1) {
        var r = url.split("?")[1].match(reg);
        if (r != null) return unescape(r[2]);
        return null;
      }
      return null;
    },
    async getData() {
      let timeMath = (new Date().getTime() / 1000).toFixed(0);
      // 重定向地址
      let redirect_uri_new = `${this.fun.getSiteRoot()}/addons/yun_shop/?menu#/self_bartending_store/${this.$route.query.selfBartendStoreId}?i=${this.fun.getKeyByI()}&type=${this.fun.getTyep()}&selfTime=${timeMath}&device_id=${this.$route.query.device_id}`;
      let json = { is_pc_qrcode: 1, yz_redirect: base64_encode(redirect_uri_new) };
      let { data, msg, result } = await $http.post("member.login.index", json, ".");
      if (result) {
      } else {
        if (data.status == 9) {
          let url = msg.url;
          if (url) {
            this.appid = this.getParam("appid", url);
            this.redirect_uri = this.getParam("redirect_uri", url);
            this.scope = this.getParam("scope", url);
            this.state = this.getParam("state", url);
          }
          this.login_obj = new WxLogin({
            id: "login_code",
            appid: this.appid,
            scope: this.scope,
            redirect_uri: encodeURIComponent(this.redirect_uri),
            state: this.state
          });
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.selfBartendLogin {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  .impowerBox .qrcode {
    width: 350px;
  }
}
</style>
